package com.demo.framework.widget;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.content.DialogInterface.OnClickListener;

import android.widget.Button;
import android.widget.TextView;

import com.demo.app.R;

/**
 * 
* @ClassName: AlertDialogUtils 
* @Description: TODO(创建自定义样式的 dialog) 
* @author 谢云腾
* @date 2013-3-25 下午03:43:05 
* @version 1.0
 */
public class AlertDialogUtil {
    
    /**
     * confirm对话框
     * 
     * @param context
     * @param title
     * @param msg
     * @param positiveMsg
     * @param negativeMsg
     * @param pl
     * @param nl
     */
    public static void confirm(final Context context, String title, String msg, String positiveMsg, String negativeMsg, OnClickListener pl,
            OnClickListener nl) {
        AlertDialog.Builder tDialog = new AlertDialog.Builder(context);
        tDialog.setTitle(title);
        tDialog.setMessage(msg);
        tDialog.setPositiveButton(positiveMsg, pl);
        tDialog.setNegativeButton(negativeMsg, nl);
        tDialog.setInverseBackgroundForced(false);
        tDialog.setCancelable(true);
        tDialog.show();
    }


    /**
     * confirm对话框
     * 
     */
    public static void confirm(final Context context, String msg, String ensure,String positiveMsg, OnClickListener pl) {
        AlertDialog.Builder tDialog = new AlertDialog.Builder(context);
        tDialog.setTitle("温馨提示");
        tDialog.setMessage(msg);
        tDialog.setPositiveButton(ensure, pl);
        tDialog.setNegativeButton(positiveMsg, null);
        tDialog.setInverseBackgroundForced(false);
        tDialog.setCancelable(true);
        tDialog.show();
    }

    /**
     * 对话框
     * @param context
     * @param strTitle
     * @param strText
     * @param icon
     * @param pl
     */
    public static void showDialog(Context context, String msg, int icon,String positiveMsg, OnClickListener ensureListener) {
        AlertDialog.Builder tDialog = new AlertDialog.Builder(context);
        tDialog.setIcon(icon);
        tDialog.setTitle("温馨提示");
        tDialog.setMessage(msg);
        tDialog.setPositiveButton(positiveMsg, ensureListener);
        tDialog.show();
    }

    public static void showDialog(Context context, String strTitle, String strText, OnClickListener pl) {
        AlertDialog.Builder tDialog = new AlertDialog.Builder(context);
        tDialog.setTitle(strTitle);
        tDialog.setMessage(strText);
        tDialog.setPositiveButton("确定", pl);
        tDialog.show();
    }
    
    
    //自定义  AlertDialog 样式
    //--------------------------------------------------------------------------------------------------
    
    /**
     *  创建一个按钮的对话框
     * @param context
     * @param title
     * @param info
     * @param btn1name
     * @param onYesBtnClicked
     * @return
     */
    public static AlertDialog createCustomAlertDialog(Context context,String title, String info,
            String btnStr,  View.OnClickListener onYesBtnClicked) {
        final AlertDialog dlg = new AlertDialog.Builder(context).create();
        dlg.show();
        dlg.setCancelable(false);
        dlg.setContentView(R.layout.layout_alertdialog);

        TextView alertTitle = (TextView) dlg.findViewById(R.id.alerttitle);
        alertTitle.setText(title);
        
        TextView alertText = (TextView) dlg.findViewById(R.id.text_info);
        alertText.setText(info);
        alertText.setGravity(android.view.Gravity.LEFT);
        
        Button btnYes = (Button) dlg.findViewById(R.id.button_yes);
        btnYes.setGravity(Gravity.CENTER_HORIZONTAL);
        
        Button btnCancel = (Button) dlg.findViewById(R.id.button_no);
        btnCancel.setVisibility(android.view.View.GONE);
        btnYes.setVisibility(android.view.View.VISIBLE);
        btnYes.setText(btnStr);
        btnYes.setOnClickListener(onYesBtnClicked);
        return dlg;
    }

    
    /**
     * 创建一个 两个按钮的对话框
     * @param context
     * @param title
     * @param info
     * @param btn1name
     * @param btn2name
     * @param onLeftBtnClicked
     * @param onRightBtnClicked
     */
    public static AlertDialog createCustomAlertDialog(Context context, String title,
            String info,String btnLeftStr, String btnRightStr, 
            View.OnClickListener onLeftBtnClicked,
            View.OnClickListener onRightBtnClicked) {
        // TODO Auto-generated method stub
        final AlertDialog dlg = new AlertDialog.Builder(context).create();
        dlg.show();
        dlg.setCancelable(false);
        dlg.setContentView(R.layout.layout_alertdialog);

        TextView alertTitle = (TextView) dlg.findViewById(R.id.alerttitle);
        alertTitle.setText(title);
        
        TextView alertText = (TextView) dlg.findViewById(R.id.text_info);
        alertText.setText(info);
        alertText.setGravity(android.view.Gravity.LEFT);
        
        Button btnYes = (Button) dlg.findViewById(R.id.button_yes);
        Button btnCancel = (Button) dlg.findViewById(R.id.button_no);
        btnYes.setVisibility(android.view.View.VISIBLE);
        btnCancel.setVisibility(android.view.View.VISIBLE);
    
        btnYes.setText(btnLeftStr);
        btnCancel.setText(btnRightStr);
        btnYes.setOnClickListener(onLeftBtnClicked);
        btnCancel.setOnClickListener(onRightBtnClicked);
        return dlg;
    }
    
    
    //调用
    /**
     *      AlertDialog ad
            btn2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ad = CustomAlertDialogUtils.createAlertDialogWithoutTitle(CustomAlertDialog.this,"提示", "是否邀请全部好友？", "确 定",new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        ad.dismiss();
                    }
                });
            }
        });
        
        btn3.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ad = CustomAlertDialogUtils.createAlertDialogWithTitle(CustomAlertDialog.this, "提示", "您有新好友，是否更新？", "确定", "取消", new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        System.out.println("OK");
                    }
                }, new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        System.out.println("ON");
                    }
                });
            }

        });
     */
}
